package com.company.cloud.club.modules.controller;

import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.cloud.club.modules.constants.ClubActivityStates;
import com.company.cloud.club.modules.constants.ClubMemberType;
import com.company.cloud.club.modules.core.dto.ListParam;
import com.company.cloud.club.modules.core.dto.Result;
import com.company.cloud.club.modules.core.util.DateUtil;
import com.company.cloud.club.modules.core.util.ValidateUtil;
import com.company.cloud.club.modules.db.dao.ArtArtistInfoMapper;
import com.company.cloud.club.modules.db.dao.FileInfoMapper;
import com.company.cloud.club.modules.db.dao.ProductInfoMapper;
import com.company.cloud.club.modules.db.domain.*;
import com.company.cloud.club.modules.dto.ConditionBo;
import com.company.cloud.club.modules.dto.IdQuery;
import com.company.cloud.club.modules.dto.LayTableResult;
import com.company.cloud.club.modules.dto.activity.ActivityBo;
import com.company.cloud.club.modules.dto.club.ClubBo;
import com.company.cloud.club.modules.dto.collection.CollectionBo;
import com.company.cloud.club.modules.dto.product.ProductArtistBo;
import com.company.cloud.club.modules.service.*;
import com.company.cloud.club.modules.utils.DataUtils;
import com.company.cloud.club.modules.utils.LoginContextUtils;
import com.company.cloud.club.modules.vo.*;
import com.company.cloud.common.auth.annotation.Login;
import com.company.cloud.common.auth.annotation.StaffLogc;
import com.company.cloud.common.utils.StrSplitUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Zookeeper
 */
@Api(tags = "社区")
@RequestMapping("/club")
@RestController
public class ClubController {

    @Autowired
    private PraiseService praiseService;

    @Autowired
    private RecommendService recommendService;

    @Autowired
    private ClubInfoService clubInfoService;

    @Autowired
    private ClubMemberService clubMemberService;

    @Autowired
    private ClubActivityService clubActivityService;

    @Autowired
    private CollectionService collectionService;

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private FileInfoMapper fileInfoMapper;

    @Autowired
    private ClubActivityRelativeService clubActivityRelativeService;

    @Autowired
    private ProductInfoMapper productInfoMapper;

    @Autowired
    private FriendDynamicService friendDynamicService;

    @Autowired
    private ArtArtistInfoMapper artArtistInfoMapper;

    /**
     * 所有交流圈分页列表
     *
     * @param params
     * @return
     */
    @GetMapping(value = "/admin/list")
    public LayTableResult adminList(@Valid @ModelAttribute ClubInfo params) {
        Integer currentUserId = LoginContextUtils.getUserId();

        List<ClubVo> list = new ArrayList<>();
        params.setDeleted(0);
        params.setSug(null);

        Integer currentPage = params.getCurrentPage();
        Integer pageSize = params.getPageSize();
        Integer begin = (currentPage - 1) * pageSize;
        IPage<ClubInfo> page = clubInfoService.page(new Page<>(begin, pageSize), new QueryWrapper<>(params).select().orderByDesc("sort"));
        int count = clubInfoService.count(new QueryWrapper<>(params));
        for (ClubInfo clubInfo : page.getRecords()) {
            Integer memberNum = clubInfoService.countMember(clubInfo.getId());
            ClubVo clubVo = new ClubVo(clubInfo.getId(), clubInfo.getName(), clubInfo.getAvatar(), memberNum);
            clubVo.setIsSug(clubInfo.getSug());
            clubVo.setVirtualHuman(clubInfo.getVirtualHuman());
            clubVo.setSort(clubInfo.getSort());
            ClubActivity activity = clubActivityService.getLastClubActivity(clubInfo.getId());
            if (ValidateUtil.isValid(activity)) {
                ActivityVo activityVo = new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner());
                activityVo.setId(activity.getId());
                activityVo.setSort(activity.getSort());
                activityVo.setPrizeTest(activity.getPrizeTest());
                activityVo.setVirtualHuman(activity.getVirtualHuman());
                clubVo.setActivityVo(activityVo);
            }
            list.add(clubVo);
        }
        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", list, count);
    }

    /**
     * 活动列表
     */
    @GetMapping(value = "/admin/activity/list")
    public LayTableResult adminActivityList(@Valid @ModelAttribute ClubActivity params, HttpServletRequest request) {
        List<ActivityVo> list = new ArrayList<>();
        Integer currentPage = params.getCurrentPage();
        Integer pageSize = params.getPageSize();
        params.setDeleted(0);
        IPage<ClubActivity> page = clubActivityService.page(new Page<>(currentPage, pageSize), new QueryWrapper<>(params).select().orderByDesc("sort"));
        int count = clubActivityService.count(new QueryWrapper<>(params));
        for (ClubActivity activity : page.getRecords()) {
            ActivityVo activityVo = new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner(), activity.getJoinNum());
            Integer userId = activity.getUserId();
            UserInfo userInfo = userInfoService.getById(userId);
            activityVo.setId(activity.getId());
            activityVo.setHot(activity.getHot());
            activityVo.setHome(0);

            if (ValidateUtil.isValid(activity.getHome())) {
                activityVo.setHome(activity.getHome());
            }

            activityVo.setVirtualHuman(activity.getVirtualHuman());
            activityVo.setPrizeTest(activity.getPrizeTest());
            activityVo.setAuthor(userInfo.getNickName());
            activityVo.setState(ClubActivityStates.getState(activity.getStartTime(), activity.getEndTime()));
            activityVo.setLocation(activity.getLocation());
            activityVo.setSort(activity.getSort());
            activityVo.setNum(recommendService.countComment(activity.getId()));
            activityVo.setCtime(DateUtil.timeToStr(activity.getTimeCreated(), DateUtil.DATE_MINI_PATTERN));
            activityVo.setStartTime(DateUtil.timeToStr(activity.getStartTime(), DateUtil.DATE_MINI_PATTERN));
            activityVo.setEndTime(DateUtil.timeToStr(activity.getEndTime(), DateUtil.DATE_MINI_PATTERN));
            list.add(activityVo);
        }

        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", list, count);
    }

    /**
     * 活动成员列表
     */
    @GetMapping(value = "/admin/activity/member/list")
    public LayTableResult adminActivityList(@Valid @ModelAttribute ListParam params, HttpServletRequest request) {

        String activityId = params.getId();
        ClubActivity activity = clubActivityService.getById(activityId);
        if (ValidateUtil.isEmpty(activity) || activity.getDeleted() != 0) {
            throw new RuntimeException("活动不存在");
        }

        Integer currentPage = params.getCurrentPage();
        Integer pageSize = params.getPageSize();
        Integer begin = (currentPage - 1) * pageSize;

        List<UserInfo> userInfoList = recommendService.pageUserByParentId(activityId, begin, pageSize);
        Integer count = recommendService.pageCountByParentId(activityId);

        List<ClubMemberVo> memberList = new ArrayList<>();
        for (UserInfo userInfo : userInfoList) {
            if (ValidateUtil.isValid(userInfo)) {
                ClubMemberVo vo = new ClubMemberVo(userInfo.getId(), userInfo.getNickName(), userInfo.getHeadImg(), "成员");
                memberList.add(vo);
            }
        }

        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", memberList, count);

    }

    /**
     * 交流圈成员列表
     */
    @GetMapping(value = "/admin/member/list")
    public LayTableResult adminClubMemberList(@Valid @ModelAttribute ListParam params, HttpServletRequest request) {

        String clubId = params.getId();
        ClubInfo clubInfo = clubInfoService.getById(clubId);
        if (ValidateUtil.isEmpty(clubInfo) || clubInfo.getDeleted() != 0) {
            throw new RuntimeException("交流圈不存在");
        }

        Integer currentPage = params.getCurrentPage();
        Integer pageSize = params.getPageSize();
        Integer begin = (currentPage - 1) * pageSize;

        List<ClubMemberVo> memberList = new ArrayList<>();
        List<ClubMember> userInfoList = clubMemberService.pageByClubId(clubId, begin, pageSize);
        Integer count = clubMemberService.countByClubId(clubId);

        for (ClubMember clubMember : userInfoList) {
            Integer userId = clubMember.getUserId();
            UserInfo userInfo = userInfoService.getById(userId);
            if (ValidateUtil.isValid(userInfo)) {
                ClubMemberVo vo = new ClubMemberVo(userInfo.getId(), userInfo.getNickName(), userInfo.getHeadImg(), clubMember.getType());
                vo.setPhone(userInfo.getMobile());
                memberList.add(vo);
            }
        }

        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", memberList, count);

    }

    /**
     * 创建交流圈
     */
    @PostMapping(value = "create")
    @StaffLogc(title = "创建交流圈", action = "创建交流圈", actionAdo = "交流圈")
    public Result create(@RequestBody ClubBo bo) {
        Integer currentUserId = LoginContextUtils.getUserId();

        ClubInfo info = new ClubInfo(0);
        info.setName(bo.getName());
        info.setAvatar(bo.getAvatar());
        info.setIntro(bo.getIntro());
        info.setVirtualHuman(bo.getVirtualHuman());
        info.setSug(bo.getIsSug());
        info.setSort(bo.getSort());

        boolean flag = clubInfoService.save(info);

        if (!flag) {
            throw new RuntimeException("交流圈创建失败");
        }

        ClubMember clubMaster = new ClubMember(0);
        clubMaster.setUserId(bo.getClubMasterId());
        clubMaster.setType(ClubMemberType.MASTER);
        clubMaster.setClubId(info.getId());
        clubMemberService.save(clubMaster);

        List<Integer> clubDirectorIds = bo.getClubDirectorIds();
        for (Integer userId : clubDirectorIds) {
            ClubMember clubDirector = new ClubMember(0);
            clubDirector.setUserId(userId);
            clubDirector.setType(ClubMemberType.DIRECTOR);
            clubDirector.setClubId(info.getId());
            clubMemberService.save(clubDirector);
        }

        List<Integer> clubMemberIds = bo.getClubMemberIds();
        for (Integer userId : clubMemberIds) {
            ClubMember clubMember = new ClubMember(0);
            clubMember.setUserId(userId);
            clubMember.setType(ClubMemberType.MEMBER);
            clubMember.setClubId(info.getId());
            clubMemberService.save(clubMember);
        }

        String activityId = bo.getActivityId();
        ClubActivity activity = clubActivityService.getById(activityId);
        if (ValidateUtil.isValid(activity)) {
            ClubActivityRelative relative = new ClubActivityRelative(0);
            relative.setClubId(info.getId());
            relative.setActivityId(activityId);
            clubActivityRelativeService.save(relative);
        }

        return Result.ok(info.getId());

    }

    /**
     * 编辑交流圈
     */
    @PostMapping(value = "update")
    @StaffLogc(title = "编辑交流圈", action = "编辑交流圈", actionAdo = "交流圈")
    public Result update(@Valid @RequestBody ClubBo bo) {
        Integer currentUserId = LoginContextUtils.getUserId();

        ClubInfo info = clubInfoService.getById(bo.getId());

        if (ValidateUtil.isEmpty(info) || info.getDeleted() != 0) {
            throw new RuntimeException("交流圈不存在");
        }

        info.setName(bo.getName());
        info.setAvatar(bo.getAvatar());
        info.setIntro(bo.getIntro());
        info.setSug(bo.getIsSug());
        info.setVirtualHuman(bo.getVirtualHuman());
        info.setSort(bo.getSort());

        boolean flag = clubInfoService.saveOrUpdate(info);
        if (!flag) {
            throw new RuntimeException("交流圈编辑失败");
        }

        boolean memberFlag = clubMemberService.deleteClubMember(info.getId(), ClubMemberType.MASTER);
        if (memberFlag) {
            ClubMember clubMember = new ClubMember(0);
            clubMember.setUserId(bo.getClubMasterId());
            clubMember.setType(ClubMemberType.MASTER);
            clubMember.setClubId(info.getId());
            clubMemberService.save(clubMember);
        }

        clubMemberService.deleteClubMember(info.getId(), ClubMemberType.DIRECTOR);
        List<Integer> clubDirectorIds = bo.getClubDirectorIds();
        for (Integer userId : clubDirectorIds) {
            ClubMember clubDirector = new ClubMember(0);
            clubDirector.setUserId(userId);
            clubDirector.setType(ClubMemberType.DIRECTOR);
            clubDirector.setClubId(info.getId());
            clubMemberService.save(clubDirector);
        }

        clubMemberService.deleteClubMember(info.getId(), ClubMemberType.MEMBER);
        List<Integer> clubMemberIds = bo.getClubMemberIds();
        for (Integer userId : clubMemberIds) {
            ClubMember clubMember = new ClubMember(0);
            clubMember.setUserId(userId);
            clubMember.setType(ClubMemberType.MEMBER);
            clubMember.setClubId(info.getId());
            clubMemberService.save(clubMember);
        }

        return Result.ok(info.getId());
    }

    /**
     * 删除交流圈
     */
    @PostMapping(value = "remove")
    @StaffLogc(title = "删除交流圈", action = "删除交流圈", actionAdo = "交流圈")
    public Result remove(@RequestBody IdQuery bo) {
        Integer currentUserId = LoginContextUtils.getUserId();
        boolean flag = clubInfoService.removeClub(bo.getId());
        return Result.ok(flag);
    }

    /**
     * 交流圈详情
     */
    @GetMapping(value = "detail")
    public Result detail(@ModelAttribute IdQuery vo, HttpServletRequest request) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();

        ClubInfo clubInfo = clubInfoService.getById(vo.getId());
        if (ValidateUtil.isEmpty(clubInfo)) {
            throw new RuntimeException("交流圈不存在");
        }

        Integer memberNum = clubInfoService.countMember(clubInfo.getId());
        ClubVo clubVo = new ClubVo(clubInfo.getId(), clubInfo.getName(), clubInfo.getAvatar(), memberNum);
        clubVo.setIsSug(clubInfo.getSug());
        clubVo.setVirtualHuman(clubInfo.getVirtualHuman());
        clubVo.setIntro(clubInfo.getIntro());
        clubVo.setSort(clubInfo.getSort());
        clubVo.setIsColl(ValidateUtil.isValid(clubMemberService.selectByClubIdAndUserId(clubInfo.getId(), currentUserId)));
        List<ClubMember> memberList = clubMemberService.selectByClubId(clubInfo.getId());
        for (ClubMember member : memberList) {
            Integer userId = member.getUserId();
            UserInfo userInfo = userInfoService.getById(userId);
            if (ValidateUtil.isValid(userInfo)) {
                clubVo.addMember(new ClubMemberVo(userId, userInfo.getNickName(), userInfo.getHeadImg(), member.getType()));
            }
            if (ClubMemberType.MASTER.equals(member.getType())) {
                clubVo.setClubMasterId(userId);
            }
        }

        ClubActivity lastClubActivity = clubActivityService.getLastClubActivity(clubInfo.getId());
        if (ValidateUtil.isValid(lastClubActivity)) {
            clubVo.setActivityVo(new ActivityVo(lastClubActivity.getTitle(), lastClubActivity.getLabel(), lastClubActivity.getBanner()));
        }

        return Result.ok(clubVo);

    }

    /**
     * 推荐交流圈
     */
    @GetMapping(value = "circle")
    public Result circle(HttpServletRequest request) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();
        List<ClubVo> list = new ArrayList<>();
        List<ClubInfo> sugList = clubInfoService.querySug();
        for (ClubInfo clubInfo : sugList) {
            // 用户登录 并且已关注该交流圈时 不显示
          /*  if (currentUserId != 0) {
                Boolean flag = clubMemberService.isColled(clubInfo.getId(), currentUserId);
                if (flag) {
                    continue;
                }
            }*/
            Integer memberNum = clubInfoService.countMember(clubInfo.getId());
            list.add(new ClubVo(clubInfo.getId(), clubInfo.getName(), clubInfo.getAvatar(), memberNum));
        }
        return Result.ok(list);
    }

    /**
     * 圈全部
     */
    @GetMapping(value = "recommend/all")
    public LayTableResult allList(@Valid @ModelAttribute ListParam params) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();
        String clubId = params.getId();

        Integer currentPage = params.getCurrentPage();
        Integer pageSize = params.getPageSize();
        Integer begin = (currentPage - 1) * pageSize;

        List<RecommendCard> cardList = recommendService.selectByClubId(clubId, begin, pageSize);
        int count = recommendService.countByClubId(clubId);

        List<RecommendCardVo> list = new ArrayList<>();
        for (RecommendCard card : cardList) {
            if (card.getIsPublish() != 2) {
                continue;
            }
            RecommendCardVo vo = new RecommendCardVo();
            initRecommendCardVo(vo, card, currentUserId);
            list.add(vo);
        }

        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", list, count);

    }

    /**
     * 圈精华
     */
    @GetMapping(value = "recommend/essence")
    public LayTableResult recommendList(@Valid @ModelAttribute ListParam params) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();

        Integer currentPage = params.getCurrentPage();
        Integer pageSize = params.getPageSize();
        Integer begin = (currentPage - 1) * pageSize;
        String clubId = params.getId();

        List<RecommendCard> cardList = recommendService.pageEssenceAndClub(clubId, begin, pageSize);
        int count = recommendService.countEssenceAndClub(clubId);

        List<RecommendCardVo> list = new ArrayList<>();
        for (RecommendCard card : cardList) {

            if (card.getIsPublish() != 2) {
                continue;
            }

            RecommendCardVo vo = new RecommendCardVo();
            initRecommendCardVo(vo, card, currentUserId);
            list.add(vo);
        }

        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", list, count);

    }


    /**
     * 所有交流圈
     *
     * @param params
     * @return
     */
    @GetMapping(value = "all/query")
    public Result queryAll(@Valid @ModelAttribute ClubInfo params) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();
        List<ClubVo> list = new ArrayList<>();
        params.setDeleted(0);
        params.setSug(params.getSug() == 0 ? null : 1);
        List<ClubInfo> sugList = clubInfoService.list(new QueryWrapper<>(params).select().orderByDesc("sort"));
        for (ClubInfo clubInfo : sugList) {
            // 用户登录 并且已关注该交流圈时 不显示
            if (currentUserId != 0) {
                Boolean flag = clubMemberService.isColled(clubInfo.getId(), currentUserId);
                if (flag) {
                    continue;
                }
            }

            Integer memberNum = clubInfoService.countMember(clubInfo.getId());
            ClubVo clubVo = new ClubVo(clubInfo.getId(), clubInfo.getName(), clubInfo.getAvatar(), memberNum);
            clubVo.setVirtualHuman(clubInfo.getVirtualHuman());
            list.add(clubVo);
        }
        return Result.ok(list);
    }

    @ApiOperation("用户（我的）详情")
    @GetMapping(value = "/person/detail")
    public Result personDetail(@Valid @ModelAttribute IdQuery bo) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();

        String id = bo.getId();
        if (ValidateUtil.isEmpty(id)) {
            id = String.valueOf(currentUserId);
        }

        UserInfo userInfo = userInfoService.getById(id);
        if (ValidateUtil.isEmpty(userInfo)) {
            throw new RuntimeException("当前用户不存在");
        }

        PersonVo vo = new PersonVo();
        vo.setAvatar(userInfo.getHeadImg());
        vo.setNickname(userInfo.getNickName());
        vo.setIsAuthor(currentUserId == Integer.parseInt(id));
        vo.setFansNum(collectionService.countFunsNum(id));
        vo.setRecomNum(collectionService.countRecomNum(Integer.valueOf(id)));
        vo.setIsRecom(collectionService.isColled(id, currentUserId));

        return Result.ok(vo);

    }

    @ApiOperation("用户（我的）交流圈")
    @GetMapping(value = "/mime")
    public LayTableResult myClub(@Valid @ModelAttribute ListParam bo) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();

        Integer uid = currentUserId;
        String userId = bo.getId();
        if (ValidateUtil.isValid(userId)) {
            uid = Integer.parseInt(userId);
            UserInfo userInfo = userInfoService.getById(uid);
            if (ValidateUtil.isEmpty(userInfo)) {
                uid = currentUserId;
            }
        }

        Integer currentPage = bo.getCurrentPage();
        Integer pageSize = bo.getPageSize();
        Integer begin = (currentPage - 1) * pageSize;

        List<ClubVo> list = new ArrayList<>();
        List<ClubMember> memberList = clubMemberService.pageByUserId(uid, begin, pageSize);
        int count = clubMemberService.countByUserId(uid);

        for (ClubMember clubMember : memberList) {
            String resId = clubMember.getClubId();
            ClubInfo clubInfo = clubInfoService.getById(resId);
            if (ValidateUtil.isValid(clubInfo)) {
                ClubVo vo = new ClubVo(resId, clubInfo.getName(), clubInfo.getAvatar());
                vo.setVirtualHuman(clubInfo.getVirtualHuman());
                vo.setNum(clubInfoService.countMember(clubInfo.getId()));
                list.add(vo);
            }
        }

        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", list, count);

    }

    /**
     * 我加入的交流圈
     *
     * @return
     */
    @GetMapping(value = "mime/query")
    public Result queryMime() {
        Integer currentUserId = LoginContextUtils.getUserId();

        List<ClubVo> list = new ArrayList<>();
        List<ClubMember> collList = clubMemberService.selectByUserId(currentUserId);
        for (ClubMember coll : collList) {
            String clubId = coll.getClubId();
            ClubInfo clubInfo = clubInfoService.getById(clubId);
            if (ValidateUtil.isValid(clubInfo)) {
                Integer memberNum = clubInfoService.countMember(clubInfo.getId());
                ClubVo clubVo = new ClubVo(clubInfo.getId(), clubInfo.getName(), clubInfo.getAvatar(), memberNum);
                list.add(clubVo);
            }
        }

        return Result.ok(list);
    }

    /**
     * 创建活动
     */
    @PostMapping(value = "/activity/create")
    @StaffLogc(title = "创建活动", action = "创建活动", actionAdo = "社区活动")
    public Result create(@RequestBody ActivityBo bo) {
        LoginContextUtils.getUserId();

        ClubActivity activity = new ClubActivity(0);
        activity.setTitle(bo.getTitle());
        activity.setLabel(bo.getLabel());
        activity.setBanner(bo.getBanner());
        activity.setIntro(bo.getIntro());
        activity.setStartTime(bo.getStartTime());
        activity.setEndTime(bo.getEndTime());
        activity.setHot(bo.getHot());
        activity.setPrizeTest(bo.getPrizeTest());
        activity.setVirtualHuman(bo.getVirtualHuman());
        activity.setLocation(bo.getLocation());
        activity.setHome(bo.getHome());
        activity.setStates("0");
        activity.setUserId(bo.getUserId());
        activity.setJoinNum(0);
        activity.setLongitude(bo.getLongitude());
        activity.setLatitude(bo.getLatitude());
        activity.setSort(bo.getSort());
        activity.setUnionPerson(JSON.toJSONString(bo.getUnionPerson()));
        List<String> clubIds = bo.getClubIds();
        for (String clubId : clubIds) {
            ClubInfo clubInfo = clubInfoService.getById(clubId);
            if (ValidateUtil.isValid(clubInfo)) {
                if (ValidateUtil.isEmpty(clubInfo) || clubInfo.getDeleted() != 0) {
                    throw new RuntimeException("交流圈不存在");
                }
                ClubActivityRelative relative = new ClubActivityRelative(0);
                relative.setActivityId(activity.getId());
                relative.setClubId(clubId);
                clubActivityRelativeService.save(relative);
            }
        }

        boolean flag = clubActivityService.save(activity);
        if (!flag) {
            throw new RuntimeException("活动创建失败");
        }

        return Result.ok(activity.getId());
    }

    /**
     * 热门活动
     */
    @GetMapping(value = "activity/hot")
    public Result activityHot(HttpServletRequest request) {
        List<ActivityVo> list = new ArrayList<>();
        List<ClubActivity> activityList = clubActivityService.queryHot(System.currentTimeMillis());
        for (ClubActivity activity : activityList) {
            ActivityVo activityVo = new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner(), activity.getJoinNum());
            activityVo.setId(activity.getId());
            activityVo.setHot(activity.getHot());
            activityVo.setPrizeTest(activity.getPrizeTest());
            activityVo.setSort(activity.getSort());
            activityVo.setHome(activity.getHome());
            activityVo.setVirtualHuman(activity.getVirtualHuman());
            activityVo.setNum(recommendService.countComment(activity.getId()));
            activityVo.setStartTime(DateUtil.timeToStr(activity.getStartTime(), DateUtil.DATE_MINI_PATTERN));
            activityVo.setEndTime(DateUtil.timeToStr(activity.getEndTime(), DateUtil.DATE_MINI_PATTERN));
            Integer userId = activity.getUserId();
            UserInfo userInfo = userInfoService.getById(userId);
            if (ValidateUtil.isValid(userInfo)) {
                activityVo.setAuthor(userInfo.getNickName());
                activityVo.setAuthorAvatar(userInfo.getHeadImg());
            }
            list.add(activityVo);
        }
        return Result.ok(list);
    }

    /**
     * 更新活动
     */
    @PostMapping(value = "/activity/update")
    @StaffLogc(title = "更新活动", action = "更新活动", actionAdo = "社区活动")
    public Result update(@RequestBody ActivityBo bo) {
        LoginContextUtils.getUserId();

        ClubActivity activity = clubActivityService.getById(bo.getId());
        if (ValidateUtil.isEmpty(activity) || activity.getDeleted() != 0) {
            throw new RuntimeException("活动不存在");
        }

        activity.setTitle(bo.getTitle());
        activity.setLabel(bo.getLabel());
        activity.setBanner(bo.getBanner());
        activity.setIntro(bo.getIntro());
        activity.setStartTime(bo.getStartTime());
        activity.setEndTime(bo.getEndTime());

        activity.setPrizeTest(bo.getPrizeTest());
        activity.setVirtualHuman(bo.getVirtualHuman());
        activity.setHot(bo.getHot());
        activity.setLocation(bo.getLocation());
        activity.setLongitude(bo.getLongitude());
        activity.setHome(bo.getHome());
        activity.setLatitude(bo.getLatitude());
        activity.setSort(bo.getSort());
        activity.setUserId(bo.getUserId());
        activity.setUnionPerson(JSON.toJSONString(bo.getUnionPerson()));
        List<String> clubIds = bo.getClubIds();
        clubActivityRelativeService.removeByActivityId(activity.getId());
        for (String clubId : clubIds) {
            ClubInfo clubInfo = clubInfoService.getById(clubId);
            if (ValidateUtil.isValid(clubInfo)) {
                if (ValidateUtil.isEmpty(clubInfo) || clubInfo.getDeleted() != 0) {
                    throw new RuntimeException("交流圈不存在");
                }
                ClubActivityRelative relative = new ClubActivityRelative(0);
                relative.setActivityId(activity.getId());
                relative.setClubId(clubId);
                clubActivityRelativeService.save(relative);
            }
        }

        boolean flag = clubActivityService.saveOrUpdate(activity);
        if (!flag) {
            throw new RuntimeException("活动修改失败");
        }

        return Result.ok(activity.getId());
    }

    /**
     * 活动详情
     */
    @GetMapping(value = "activity/detail")
    public Result activityDetail(@ModelAttribute IdQuery vo, HttpServletRequest request) {
        ClubActivity activity = clubActivityService.getById(vo.getId());
        if (ValidateUtil.isEmpty(activity) || activity.getDeleted() != 0) {
            throw new RuntimeException("活动不存在");
        }

        ActivityVo activityVo = new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner(), activity.getJoinNum());
        activityVo.setId(activity.getId());
        activityVo.setHot(activity.getHot());
        activityVo.setLongitude(activity.getLongitude());
        activityVo.setLatitude(activity.getLatitude());
        activityVo.setPrizeTest(activity.getPrizeTest());
        activityVo.setSort(activity.getSort());
        activityVo.setVirtualHuman(activity.getVirtualHuman());
        activityVo.setNum(recommendService.countComment(activity.getId()));
        activityVo.setStartTime(String.valueOf(activity.getStartTime()));
        activityVo.setEndTime(String.valueOf(activity.getEndTime()));
        activityVo.setLongitude(activity.getLongitude());
        activityVo.setHome(activity.getHome());
        activityVo.setLatitude(activity.getLatitude());
        Integer userId = activity.getUserId();
        activityVo.setUserId(userId);
        UserInfo userInfo = userInfoService.getById(userId);
        if (ValidateUtil.isValid(userInfo)) {
            activityVo.setAuthor(userInfo.getNickName());
            activityVo.setAuthorAvatar(userInfo.getHeadImg());
        }

        List<ClubActivityRelative> list = clubActivityRelativeService.selectByActivityId(activity.getId());
        for (ClubActivityRelative relative : list) {
            String clubId = relative.getClubId();
            ClubInfo clubInfo = clubInfoService.getById(clubId);
            if (ValidateUtil.isValid(clubInfo)) {
                List<ClubMember> memberList = clubMemberService.selectByClubId(clubId);
                activityVo.addClubVo(new ClubVo(clubInfo.getId(), clubInfo.getName(), clubInfo.getAvatar(), memberList.size()));
            }
        }

        String unionPerson = activity.getUnionPerson();
        List<Integer> unionUserList = JSON.parseArray(unionPerson, Integer.class);
        if (ValidateUtil.isValid(unionUserList)) {
            for (Integer uid : unionUserList) {
                UserInfo uInfo = userInfoService.getById(uid);
                if (ValidateUtil.isValid(uInfo)) {
                    if (ValidateUtil.isEmpty(uInfo.getHeadImg())) {
                        uInfo.setHeadImg("https://artshanghai.oss-cn-shanghai.aliyuncs.com/ui/icon-male.png");
                    }
                    activityVo.addUnionPerson(new ClubMemberVo(uInfo.getId(), uInfo.getNickName(), uInfo.getHeadImg(), "user"));
                }
            }
        }

        return Result.ok(activityVo);
    }

    /**
     * 删除活动
     */
    @PostMapping(value = "activity/remove")
    @StaffLogc(title = "删除活动", action = "删除活动", actionAdo = "社区活动")
    public Result activityRemove(@RequestBody IdQuery bo) {
        Integer currentUserId = LoginContextUtils.getUserId();
        boolean flag = clubActivityService.removeActivity(bo.getId());
        return Result.ok(flag);
    }

    /**
     * 热门活动（往期）
     */
    @GetMapping(value = "activity/hot/history")
    public Result activityHotHistory(HttpServletRequest request) {
        List<ActivityVo> list = new ArrayList<>();
        List<ClubActivity> activityList = clubActivityService.queryHotHistory(System.currentTimeMillis());
        for (ClubActivity activity : activityList) {
            ActivityVo activityVo = new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner(), activity.getJoinNum());
            String pureLabel = DataUtils.removeHtmlLabel(activity.getLabel());
            activityVo.setPureLabel(pureLabel.length() <= 50 ? pureLabel : pureLabel.substring(0, 49));
            activityVo.setId(activity.getId());
            activityVo.setHot(activity.getHot());
            activityVo.setPrizeTest(activity.getPrizeTest());
            activityVo.setSort(activity.getSort());
            activityVo.setHome(activity.getHome());
            activityVo.setVirtualHuman(activity.getVirtualHuman());
            activityVo.setStartTime(String.valueOf(activity.getStartTime()));
            activityVo.setEndTime(String.valueOf(activity.getEndTime()));
            activityVo.setNum(recommendService.countComment(activity.getId()));
            Integer userId = activity.getUserId();
            UserInfo userInfo = userInfoService.getById(userId);
            if (ValidateUtil.isValid(userInfo)) {
                activityVo.setAuthor(userInfo.getNickName());
                activityVo.setAuthorAvatar(userInfo.getHeadImg());
            }
            list.add(activityVo);
        }
        return Result.ok(list);
    }

    /**
     * 活动列表
     */
    @GetMapping(value = "activity/list")
    public Result activityList(HttpServletRequest request) {
        List<ActivityVo> list = new ArrayList<>();
        List<ClubActivity> activityList = clubActivityService.queryAll();
        for (ClubActivity activity : activityList) {
            ActivityVo activityVo = new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner(), activity.getJoinNum());
            String pureLabel = DataUtils.removeHtmlLabel(activity.getLabel());
            activityVo.setPureLabel(pureLabel.length() <= 50 ? pureLabel : pureLabel.substring(0, 49));
            Integer userId = activity.getUserId();
            UserInfo userInfo = userInfoService.getById(userId);
            if (ValidateUtil.isValid(userInfo)) {
                activityVo.setId(activity.getId());
                activityVo.setHot(activity.getHot());
                activityVo.setPrizeTest(activity.getPrizeTest());
                activityVo.setSort(activity.getSort());
                activityVo.setHome(activity.getHome());
                activityVo.setVirtualHuman(activity.getVirtualHuman());
                activityVo.setAuthor(userInfo.getNickName());
                activityVo.setState(ClubActivityStates.getState(activity.getStartTime(), activity.getEndTime()));
                activityVo.setLocation(activity.getLocation());
                activityVo.setCtime(DateUtil.timeToStr(activity.getTimeCreated(), DateUtil.DATE_MINI_PATTERN));
                activityVo.setNum(recommendService.countComment(activity.getId()));
                activityVo.setStartTime(DateUtil.timeToStr(activity.getStartTime(), DateUtil.DATE_MINI_PATTERN));
                activityVo.setEndTime(DateUtil.timeToStr(activity.getEndTime(), DateUtil.DATE_MINI_PATTERN));
                list.add(activityVo);
            }
        }
        return Result.ok(list);
    }

    /**
     * 某个交流圈的活动列表
     */
    @GetMapping(value = "activity/club/list")
    public Result activityClubList(@ModelAttribute IdQuery vo, HttpServletRequest request) {
        List<ActivityVo> list = new ArrayList<>();
        List<ClubActivity> activityList = clubActivityService.queryByClubId(vo.getId());
        for (ClubActivity activity : activityList) {
            ActivityVo activityVo = new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner(), activity.getJoinNum());
            Integer userId = activity.getUserId();
            UserInfo userInfo = userInfoService.getById(userId);
            if (ValidateUtil.isValid(userInfo)) {
                activityVo.setId(activity.getId());
                activityVo.setHot(activity.getHot());
                activityVo.setPrizeTest(activity.getPrizeTest());
                activityVo.setSort(activity.getSort());
                activityVo.setHome(activity.getHome());
                activityVo.setVirtualHuman(activity.getVirtualHuman());
                activityVo.setAuthor(userInfo.getNickName());
                activityVo.setState(ClubActivityStates.getState(activity.getStartTime(), activity.getEndTime()));
                activityVo.setLocation(activity.getLocation());
                activityVo.setCtime(DateUtil.timeToStr(activity.getTimeCreated(), DateUtil.DATE_MINI_PATTERN));
                activityVo.setNum(recommendService.countComment(activity.getId()));
                activityVo.setStartTime(DateUtil.timeToStr(activity.getStartTime(), DateUtil.DATE_MINI_PATTERN));
                activityVo.setEndTime(DateUtil.timeToStr(activity.getEndTime(), DateUtil.DATE_MINI_PATTERN));
                list.add(activityVo);
            }
        }
        return Result.ok(list);
    }

    /**
     * 活动全部参与
     */
    @GetMapping(value = "activity/join/list")
    public Result activityJoinList(@Valid @ModelAttribute IdQuery bo) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();

        List<RecommendCardVo> voList = new ArrayList<>();
        List<RecommendCard> list = recommendService.queryByParentId(bo.getId());
        for (RecommendCard card : list) {

            if (card.getIsPublish() != 2) {
                continue;
            }

            RecommendCardVo vo = new RecommendCardVo();
            initRecommendCardVo(vo, card, currentUserId);
            voList.add(vo);

        }

        return Result.ok(voList);
    }

    /**
     * 今日推荐
     */
    @GetMapping(value = "today")
    public LayTableResult today(ListParam param, HttpServletRequest request) {
        Integer currentUserId = LoginContextUtils.getUserIdOrNotLogin();

        List<RecommendCardVo> list = new ArrayList<>();

        Integer currentPage = param.getCurrentPage();
        Integer pageSize = param.getPageSize();
        Integer begin = (currentPage - 1) * pageSize;

        List<RecommendCard> cardList = recommendService.selectAllDynamicToday(2, begin, pageSize);
        // int count=  recommendService.countAllDynamic(2);
        final int count = recommendService.count(new QueryWrapper<RecommendCard>().eq("is_publish", 2).eq("is_suggest", 1));
        for (RecommendCard card : cardList) {
            if (card.getIsPublish() != 2) {
                continue;
            }
            RecommendCardVo vo = new RecommendCardVo();
            initRecommendCardVo(vo, card, currentUserId);
            final String clubId = card.getClubId();
            ClubInfo clubInfo = clubInfoService.getById(clubId);
            if (ValidateUtil.isValid(clubInfo)) {
                Integer memberNum = clubInfoService.countMember(clubId);
                ClubVo club = new ClubVo(clubInfo.getId(), clubInfo.getName(), clubInfo.getAvatar(), memberNum);
                vo.setClub(club);
            }
            list.add(vo);
        }
        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", list, count);
    }

    /**
     * 画家上新
     */
    @GetMapping(value = "product/recent")
    public LayTableResult productRecent(ListParam param, HttpServletRequest request) {

        LoginContextUtils.getUserIdOrNotLogin();

        List<RecommendCardVo> list = new ArrayList<>();

        Integer currentPage = param.getCurrentPage();
        Integer pageSize = param.getPageSize();
        Integer begin = (currentPage - 1) * pageSize;

        List<ProductInfo> cardList = productInfoMapper.pageByRecent(begin, pageSize);
        Integer count = productInfoMapper.countByRecent();
        for (ProductInfo card : cardList) {
            RecommendCardVo vo = new RecommendCardVo();
            String artistNo = card.getBizValue4();
            ArtArtistInfo artArtistInfo = artArtistInfoMapper.selectByArtistNo(artistNo);
            if (ValidateUtil.isValid(artArtistInfo)) {
                vo.setNickname(artArtistInfo.getName());
                vo.setAvatar(artArtistInfo.getHeadImg());
            } else {
                vo.setNickname(card.getBizValue19());
                vo.setAvatar("https://img.artshanghaifair.com/assets/img/acCircle/Head-portrait.png");
            }
            vo.setId(card.getProductNo());
            vo.addImg(card.getImage());
            vo.setClubId(artistNo);
            vo.setTitle(card.getName());
            vo.setCtime(DateUtil.formatTime(card.getCdt()));
            vo.setParentId(artistNo);
            list.add(vo);
        }

        return new LayTableResult(Result.SUCCESS_CODE, "获取成功", list, count);
    }

    /**
     * 画家作品列表
     *
     * @param param
     * @param request
     * @return
     */
    @GetMapping(value = "product/artist")
    public Result productArtist(IdQuery param, HttpServletRequest request) {
        ProductArtistBo bo = new ProductArtistBo();

        String artistNo = param.getId();

        ArtArtistInfo artArtistInfo = artArtistInfoMapper.selectByArtistNo(artistNo);
        if (ValidateUtil.isEmpty(artArtistInfo)) {
            throw new RuntimeException("艺术家不存在.");
        }

        String name = artArtistInfo.getName();
        String avatar = artArtistInfo.getHeadImg();
        bo.setNickname(name);
        bo.setAvatar(avatar);
        bo.setLabel(artArtistInfo.getDetail());
        bo.setProductNum(productInfoMapper.countArtistProductNum(artistNo));

        List<ProductInfo> last3DaysList = productInfoMapper.selectLast3Days(artistNo);
        for (ProductInfo card : last3DaysList) {
            RecommendCardVo vo = new RecommendCardVo();
            vo.setId(card.getProductNo());
            vo.addImg(card.getImage());
            vo.setAvatar(avatar);
            vo.setClubId(card.getBizValue4());
            vo.setNickname(name);
            vo.setTitle(card.getName());
            vo.setPrice(card.getPrice());
            vo.setCtime(DateUtil.formatTime(card.getCdt()));
            bo.addLast3Days(vo);
        }

        List<ProductInfo> daysAgoList = productInfoMapper.selectDaysAgo(artistNo);
        for (ProductInfo card : daysAgoList) {
            RecommendCardVo vo = new RecommendCardVo();
            vo.setId(card.getProductNo());
            vo.addImg(card.getImage());
            vo.setAvatar(avatar);
            vo.setClubId(card.getBizValue4());
            vo.setNickname(name);
            vo.setTitle(card.getName());
            vo.setPrice(card.getPrice());
            vo.setCtime(DateUtil.formatTime(card.getCdt()));
            bo.addDaysAgoList(vo);
        }

        return Result.ok(bo);
    }


    @ApiOperation("用户点赞")
    @PostMapping(value = "/praise")
    public Result praise(@Valid @RequestBody CollectionBo query) {
        Integer currentUserId = LoginContextUtils.getUserId();

        String commentId = query.getResId();
        if (ValidateUtil.isEmpty(commentId)) {
            throw new RuntimeException("评论ID不能为空");
        }

        Praise praise = praiseService.getByCommentIdAndUserId(commentId, currentUserId);
        if (ValidateUtil.isEmpty(praise)) {

            praise = new Praise(0);
            praise.setPageUrl(query.getPageUrl());
            praise.setType(query.getType());
            praise.setCommentId(commentId);
            praise.setUserId(currentUserId);
            praiseService.save(praise);
            praiseService.addPraise(commentId);

            RecommendCard card = recommendService.getById(commentId);
            FriendDynamic fd = new FriendDynamic(0);
            fd.setUserId(currentUserId);
            fd.setDynamicUserId(currentUserId);
            fd.setTitle(card.getContent());
            fd.setType("点赞");
            friendDynamicService.save(fd);

        } else {
            praiseService.deletePraise(praise.getId());
            praiseService.subPraise(commentId);
        }

        return Result.ok();
    }

    /**
     * 交流圈模糊查询
     */
    @PostMapping(value = "condition")
    public Result condition(@Valid @RequestBody ConditionBo bo, HttpServletRequest request) {
        List<ClubVo> list = new ArrayList<>();
        List<ClubInfo> sugList = clubInfoService.selectByCondition(bo.getCondition());
        for (ClubInfo clubInfo : sugList) {
            Integer memberNum = clubInfoService.countMember(clubInfo.getId());
            list.add(new ClubVo(clubInfo.getId(), clubInfo.getName(), clubInfo.getAvatar(), memberNum));
        }
        return Result.ok(list);
    }

    /**
     * 交流圈模糊查询
     */
    @PostMapping(value = "activity/condition")
    public Result activityCondition(@Valid @RequestBody ConditionBo bo, HttpServletRequest request) {
        List<ActivityVo> list = new ArrayList<>();
        List<ClubActivity> activityList = clubActivityService.selectByCondition(bo.getCondition());
        for (ClubActivity activity : activityList) {
            ActivityVo activityVo = new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner(), activity.getJoinNum());
            activityVo.setId(activity.getId());
            activityVo.setHot(activity.getHot());
            activityVo.setSort(activity.getSort());
            Integer userId = activity.getUserId();
            UserInfo userInfo = userInfoService.getById(userId);
            if (ValidateUtil.isValid(userInfo)) {
                activityVo.setAuthor(userInfo.getNickName());
                activityVo.setAuthorAvatar(userInfo.getHeadImg());
            }
            list.add(activityVo);
        }
        return Result.ok(list);
    }

    /**
     * 用户模糊查询
     */
    @PostMapping(value = "user/condition")
    public Result userCondition(@Valid @RequestBody ConditionBo bo) {
        List<ClubMemberVo> list = new ArrayList<>();
        String condition = bo.getCondition();
        if (ValidateUtil.isEmpty(condition)) {
            List<UserInfo> conditionList = userInfoService.selectList();
            for (UserInfo userInfo : conditionList) {
                if (ValidateUtil.isEmpty(userInfo.getNickName())) {
                    userInfo.setNickName(userInfo.getMobile());
                }
                ClubMemberVo vo = new ClubMemberVo(userInfo.getId(), userInfo.getNickName(), userInfo.getHeadImg(), userInfo.getCustType());
                list.add(vo);
            }
            return Result.ok(list);
        }
        List<UserInfo> conditionList = userInfoService.selectByCondition(condition);
        for (UserInfo userInfo : conditionList) {
            ClubMemberVo vo = new ClubMemberVo(userInfo.getId(), userInfo.getNickName(), userInfo.getHeadImg(), userInfo.getCustType());
            list.add(vo);
        }
        return Result.ok(list);
    }

    private void initRecommendCardVo(RecommendCardVo vo, RecommendCard card, Integer currentUserId) {

        vo.setId(card.getId());
        vo.setTitle(card.getTitle());
        vo.setContent(card.getContent());
        vo.setCommentNum(recommendService.countComment(card.getId()));
        vo.setPraiseNum(card.getPraiseNum());
        vo.setIsAuthor(currentUserId.equals(card.getUserId()));
        vo.setIsColled(collectionService.isColled(card.getId(), currentUserId));
        vo.setIsColledAuthor(collectionService.isColled(String.valueOf(card.getUserId()), currentUserId));
        vo.setCollectionNum(collectionService.countNum("artDetail", card.getId()));
        vo.setIsPraise(praiseService.isPraise(card.getId(), currentUserId));
        vo.setCtime(DateUtil.timeToStr(card.getTimeCreated(), DateUtil.DATE_MINI_PATTERN));
        vo.setType(card.getType());
        vo.setFileType(card.getFileType());
        vo.setIsSug(card.getIsSuggest() == 1);

        String parentId = card.getParentId();
        ClubActivity activity = clubActivityService.getById(parentId);
        if (ValidateUtil.isValid(activity)) {
            vo.setActivity(new ActivityVo(activity.getTitle(), activity.getLabel(), activity.getBanner(), activity.getId()));
        }

        Integer subUserId = card.getUserId();
        UserInfo userInfo = userInfoService.getById(subUserId);
        if (ValidateUtil.isValid(userInfo)) {
            vo.setNickname(userInfo.getNickName());
            vo.setAvatar(userInfo.getHeadImg());
            vo.setLabel("");
            if(ValidateUtil.isValid(userInfo.getLabel())){
                vo.setLabel(userInfo.getLabel());
            }
            vo.setUserId(subUserId);
        }

        List<FileInfo> subImgUrlIds = fileInfoMapper.selectByResId(card.getId());
        for (FileInfo fileInfo : subImgUrlIds) {
            vo.addImg(fileInfo.getResUrl());
        }

    }

    @ApiOperation("用户（我的）关注")
    @GetMapping(value = "/pay/detail")
    public Result payDetail(@Valid @ModelAttribute IdQuery bo) {
        Integer userId = LoginContextUtils.getUserIdOrNotLogin();

        String id = bo.getId();
        if (ValidateUtil.isEmpty(id)) {
            id = String.valueOf(userId);
        }

        UserInfo userInfo = userInfoService.getById(id);
        if (ValidateUtil.isEmpty(userInfo)) {
            throw new RuntimeException("当前用户不存在");
        }

        PersonVo vo = new PersonVo();
        vo.setAvatar(userInfo.getHeadImg());
        vo.setNickname(userInfo.getNickName());
        vo.setIsAuthor(userId == Integer.parseInt(id));
        int count = 0;
        int fsCount = 0;
        final Integer integer = collectionService.countRecomNum(Integer.valueOf(id));//社区关注
        count += integer;
        final Integer funs = collectionService.countFunsNum(id);//社区粉丝
        fsCount += funs;
        PersonVo personVo = collectionService.artistInfoName(userId);
        if (ValidateUtil.isValid(personVo)) {
            final Integer integer1 = collectionService.followInfoFsNum(personVo.getNickname());//艺术家粉丝
            fsCount += integer1;
        }
        final Integer integer1 = collectionService.followInfoNum(userId);
        count += integer1;
        vo.setFansNum(fsCount);
        vo.setRecomNum(count);
        vo.setIsRecom(collectionService.isColled(id, userId));

        return Result.ok(vo);

    }

}
